define(["require", "exports", "./CommonFunction", "./EventDefinition", "./GlobalDefinition", "./MianCanvasClass", "./DataRecordClass"], function (require, exports, CommonFunction_1, EventDefinition_1, GlobalDefinition_1, MianCanvasClass_1, DataRecordClass_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    /**属性框控制类 */
    class AttributeClass {
        constructor() {
            this.CF = CommonFunction_1.CommonFunction.ins();
            this.InitAttribute();
            this.InitListenet();
            this.InitDefault();
        }
        /**根据id获取属性框各部分元素*/
        InitAttribute() {
            this.BlockWidth = this.CF.IdToElement("setBlockWidth");
            this.BlockHeight = this.CF.IdToElement("setBlockHeight");
            this.BlockWidthSum = this.CF.IdToElement("sumWidth");
            this.BlockHeightSum = this.CF.IdToElement("sumHeight");
            this.BlockStartIndex = this.CF.IdToElement("setBlockStartIndex");
            this.SetCanvasW = this.CF.IdToElement("setCanvasW");
            this.SetCanvasH = this.CF.IdToElement("setCanvasH");
            this.TagBgColor = this.CF.IdToElement("tagBgColor");
            this.Container = this.CF.IdToElement("container");
            this.CloseColoPicker = this.CF.IdToElement("closeColoPicker");
            this.SaveArrayBtn = this.CF.IdToElement("saveArrayBtn");
            this.SaveJsonBtn = this.CF.IdToElement("saveJsonBtn");
        }
        /**初始化默认值 */
        InitDefault() {
            this.BlockWidth.value = GlobalDefinition_1.GlobalDefinition.BlockWidth + "";
            this.BlockHeight.value = GlobalDefinition_1.GlobalDefinition.BlockHeight + "";
            this.BlockWidthSum.value = GlobalDefinition_1.GlobalDefinition.BlockWidthSum + "";
            this.BlockHeightSum.value = GlobalDefinition_1.GlobalDefinition.BlockHeightSum + "";
            this.BlockStartIndex.value = GlobalDefinition_1.GlobalDefinition.BlockStartIndex + "";
            this.SetCanvasH.value = GlobalDefinition_1.GlobalDefinition.MainCanvasHeight + "";
            this.SetCanvasW.value = GlobalDefinition_1.GlobalDefinition.MainCanvasWidth + "";
        }
        InitListenet() {
            //点击类型事件元素
            let clickTypeElements = [this.TagBgColor, this.Container, this.CloseColoPicker, this.SaveArrayBtn, this.SaveJsonBtn];
            //失去焦点类型事件元素
            let blurTypesElements = [this.BlockHeight, this.BlockWidth, this.SetCanvasW, this.SetCanvasH];
            this.CF.ListenerTypeEvents(clickTypeElements, EventDefinition_1.EventDefinition.CLICK, this.onCallBack.bind(this));
            this.CF.ListenerTypeEvents(blurTypesElements, EventDefinition_1.EventDefinition.BLUR, this.onCallBack.bind(this));
        }
        /**点击回调事件 */
        onCallBack(e) {
            let event = e[0];
            switch (event) {
                case this.TagBgColor:
                    let tag = this.Container.style.display;
                    if (tag == "none") {
                        this.Container.style.display = "";
                    }
                    break;
                case this.BlockHeight:
                    let height = parseInt(this.BlockHeight.value);
                    GlobalDefinition_1.GlobalDefinition.BlockHeight = height;
                    this.AdjustmentMCanvas();
                    MianCanvasClass_1.MainCanvasClass.ins().CenterMainCanvas();
                    MianCanvasClass_1.MainCanvasClass.ins().UpdateDrawGrid();
                    break;
                case this.BlockWidth:
                    let width = parseInt(this.BlockWidth.value);
                    GlobalDefinition_1.GlobalDefinition.BlockWidth = width;
                    this.AdjustmentMCanvas();
                    MianCanvasClass_1.MainCanvasClass.ins().CenterMainCanvas();
                    MianCanvasClass_1.MainCanvasClass.ins().UpdateDrawGrid();
                    break;
                case this.CloseColoPicker:
                    //关闭拾色器
                    this.Container.style.display = "none";
                    break;
                case this.SetCanvasW:
                    let m_w = parseInt(this.SetCanvasW.value);
                    MianCanvasClass_1.MainCanvasClass.ins().SetWidth(m_w);
                    MianCanvasClass_1.MainCanvasClass.ins().CenterMainCanvas();
                    this.AdjustmentBlockWH();
                    MianCanvasClass_1.MainCanvasClass.ins().UpdateDrawGrid();
                    break;
                case this.SetCanvasH:
                    let m_h = parseInt(this.SetCanvasH.value);
                    MianCanvasClass_1.MainCanvasClass.ins().SetHeight(m_h);
                    MianCanvasClass_1.MainCanvasClass.ins().CenterMainCanvas();
                    this.AdjustmentBlockWH();
                    MianCanvasClass_1.MainCanvasClass.ins().UpdateDrawGrid();
                    break;
                case this.SaveArrayBtn:
                    //同步地图数组数据
                    DataRecordClass_1.DataRecordClass.ins().MapArrUpdate();
                    this.OpenEject();
                    //alert("保存数组!");
                    break;
                case this.SaveJsonBtn:
                    DataRecordClass_1.DataRecordClass.ins().MapJsonUpdate();
                    this.OpenEject();
                    //alert("保存Json!");
                    break;
            }
        }
        /**根据当前mainCanvas返回的宽高调整图块显示数据 */
        AdjustmentBlockWH() {
            let hv = MianCanvasClass_1.MainCanvasClass.ins().ReturnCanvasHV();
            let block_w = parseInt(this.BlockWidth.value);
            let block_h = parseInt(this.BlockHeight.value);
            let sum_w = parseInt((hv.width / block_w) + "");
            let sum_h = parseInt((hv.height / block_h) + "");
            this.BlockWidthSum.value = sum_w + "";
            this.BlockHeightSum.value = sum_h + "";
            GlobalDefinition_1.GlobalDefinition.BlockHeightSum = sum_h;
            GlobalDefinition_1.GlobalDefinition.BlockWidthSum = sum_w;
            DataRecordClass_1.DataRecordClass.ins().MapDataReset(); //有图块与画布宽高的调整则重置地图数据
        }
        /**根据当前图块宽高显示数据调整mainCanvas的宽高 */
        AdjustmentMCanvas() {
            let block_w = parseInt(this.BlockWidth.value);
            let block_h = parseInt(this.BlockHeight.value);
            let sum_w = parseInt(this.BlockWidthSum.value + "");
            let sum_h = parseInt(this.BlockHeightSum.value + "");
            MianCanvasClass_1.MainCanvasClass.ins().SetWidth(block_w * sum_w);
            MianCanvasClass_1.MainCanvasClass.ins().SetHeight(block_h * sum_h);
            this.SetCanvasW.value = (block_w * sum_w) + "";
            this.SetCanvasH.value = (block_h * sum_h) + "";
        }
        /**打开导出弹框 */
        OpenEject() {
            let eject = this.CF.IdToElement("eject-area");
            let tag = eject.style.display;
            if (tag == "none") {
                eject.style.display = "";
            }
            else if (tag == "") {
                eject.style.display = "none";
            }
        }
    }
    exports.AttributeClass = AttributeClass;
});
